<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Siswa_pindah_kelas_model extends CI_Model {

	function __construct()
	{
		parent::__construct();
		$this->CI = get_instance();
	}
	//==================================================================
	function get_siswa(){
		
		$this->db->select('*');
		$this->db->from('tb_siswa'); 
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('*');
		$this->db->from('tb_siswa'); 
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}
	
	function get_siswa_kelas($id_sekolah,$id_tahunajaran,$id_tingkat,$id_kelas){
		if($id_tingkat != '' && $id_kelas != ''){
			$this->db->select('*');
			$this->db->from('tb_siswa_kelas a'); 
			$this->db->join('tb_siswa b','a.NISN=b.NISN','left'); 
			$this->db->where('a.ID_SEKOLAH',$id_sekolah);
			$this->db->where('a.ID_TAHUNAJARAN',$id_tahunajaran);
			$this->db->where('a.ID_TINGKAT',$id_tingkat);
			$this->db->where('a.ID_KELAS',$id_kelas);
			$this->db->where('b.ISAKTIF',1);
			$this->CI->flexigrid->build_query();
			
			$return['records'] = $this->db->get();
			
			$this->db->select('*');
			$this->db->from('tb_siswa_kelas a'); 
			$this->db->where('a.ID_SEKOLAH',$id_sekolah);
			$this->db->where('a.ID_TAHUNAJARAN',$id_tahunajaran);
			$this->db->where('a.ID_TINGKAT',$id_tingkat);
			$this->db->where('a.ID_KELAS',$id_kelas);
			$this->CI->flexigrid->build_query(FALSE);
			
			$return['record_count'] = $this->db->count_all_results();
		}
		else {
			// $return['records'] = array();
			$return['record_count'] = 0;
		}
		return $return;
	}
	
	function insert_siswa_kelas($data_kelas){
		$query = $this->db->insert('tb_siswa_kelas',$data_kelas);
		return $query;
	}
	
	function insert_pindah_siswa($data_pindah_kelas){
		$query = $this->db->insert('tb_siswa_pindah_kelas',$data_pindah_kelas);
		return $query;
	}
	
	function get_siswaID($nisn){
		
		//Select table column
		$this->db->select('*');
		$this->db->from('tb_siswa'); 
		// $this->db->join('tb_master_sekolah s','s.ID_SEKOLAH=p.NAMA_SEKOLAH');
		// $this->db->where('KODE_MATA_PELAJARAN',$kode_mp);
		$this->db->where('NISN',$nisn);
		//$this->db->where('ISAKTIF',1);
		$query = $this->db->get();
		return $query;
	}
	
	function update_kelas_siswa($data,$nisn){
		// $this->db->where('KODE_MATA_PELAJARAN',$kode_mp);
		// $this->db->where('TAHUN_AJARAN',$thn_ajaran);
		$this->db->where('NISN',$nisn);
		$this->db->update('tb_siswa_kelas',$data);
	}
	
}

?>
